home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Archive / Games / InputSprocketPPTest / ISpElementView.cp next >
Encoding:
Text File  |  2000-09-28  |  5.9 KB  |  250 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        ISpElementView.cp
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                xxx put dri here xxx
  13.  
  14.         Other Contact:        xxx put other contact here xxx
  15.  
  16.         Technology:            xxx put technology here xxx
  17.  
  18.     Writers:
  19.  
  20.         (BWS)    Brent Schorsch
  21.  
  22.     Change History (most recent first):
  23.  
  24.          <9>     7/17/98    BWS        add header and change creator for SDK
  25. */
  26.  
  27. /*************************************************************************************
  28.  
  29. File:      ISpElementView.cp
  30.  
  31. Copyright © 1996, 1997, 1998 Apple Computer, Inc., All Rights Reserved
  32.  
  33.  
  34. You may incorporate this sample code into your applications without
  35. restriction, though the sample code has been provided "AS IS" and the
  36. responsibility for its operation is 100% yours.  However, what you are
  37. not permitted to do is to redistribute the source as "DSC Sample Code"
  38. after having made changes. If you're going to re-distribute the source,
  39. we require that you make it clear in the source that the code was
  40. descended from Apple Sample Code, but that you've made changes.
  41.  
  42. *************************************************************************************/
  43.  
  44. #include "ISpElementView.h"
  45. #include "ISpTestGlobals.h"
  46. #include <TextUtils.h>
  47. #include "ISpPPTestTools.h"
  48.  
  49. ISpElementView::ISpElementView(LStream *inStream):LOffscreenView(inStream)
  50. {
  51.     StartIdling();
  52. }
  53.  
  54. ISpElementView::~ISpElementView()
  55. {
  56. }
  57.  
  58. ISpElementView *ISpElementView::CreateISpElementViewStream(LStream *inStream)
  59. {
  60.   return (new ISpElementView(inStream));
  61. }
  62.  
  63.  
  64. void ISpElementView::SpendTime(const EventRecord &inMacEvent)
  65. {
  66.     inMacEvent;
  67.     
  68.     Refresh();
  69.     UpdatePort();
  70. }
  71.  
  72.  
  73. void ISpElementView::DrawSelf()
  74. {
  75.     if (gElement == nil) { return; }
  76.     
  77.     Rect r;
  78.     Str255 theString;
  79.         
  80.     CalcLocalFrameRect(r);
  81.     r.left += 10;
  82.     
  83.     EraseRect(&r);
  84.     
  85.     OSStatus pollStatus;
  86.     UInt32 state = 0;
  87.     
  88.     pollStatus = ISpElement_GetSimpleState(gElement, &state);
  89.     ISpElementInfo info;
  90.     ISpElement_GetInfo(gElement, &info);
  91.     
  92.     MoveTo(r.left, r.top + 15);
  93.     DrawString("\pGlobal Error Code:  ");
  94.     NumToString(gStatus, theString);
  95.     DrawString(theString);
  96.  
  97.     MoveTo(r.left, r.top + 30);
  98.     DrawString("\pPoll Error Code:  ");
  99.     NumToString(pollStatus, theString);
  100.     DrawString(theString);
  101.  
  102.     MoveTo(r.left, r.top + 45);
  103.     DrawString("\pData:  ");
  104.     UInt32ToHexString(state, theString);
  105.     DrawString(theString);
  106.  
  107.     const rectWidth = 100;
  108.     Rect maxRect = {2,0,11,rectWidth};
  109.     Rect progRect = maxRect;
  110.     float percent;
  111.  
  112.     switch(info.theKind)
  113.     {
  114.         case kISpElementKind_Axis:
  115.         {
  116.             percent = state;
  117.             percent /= 0xffffffff;            
  118.         }
  119.         break;
  120.     
  121.         case kISpElementKind_Delta:
  122.         {
  123.             float inches = ((float) (Fixed) state) / (float) 0xffff;
  124.             
  125.             percent = 0.5 + (inches / 2);
  126.         }    
  127.     }
  128.     if (percent > 1) { percent = 1; }
  129.     if (percent < 0) { percent = 0; }
  130.     
  131.     progRect.right = rectWidth * percent;
  132.             
  133.     OffsetRect(&maxRect, r.left, r.top + 47);
  134.     OffsetRect(&progRect, r.left, r.top + 47);
  135.             
  136.     ::FrameRect(&maxRect);
  137.     ::PaintRect(&progRect);
  138.  
  139.     
  140.     MoveTo(r.left, r.top + 75);
  141.     DrawString("\pElement Num:  ");
  142.     UInt32ToHexString((unsigned long) gElement, theString);
  143.     DrawString(theString);
  144.  
  145.     MoveTo(r.left, r.top + 90);
  146.     DrawString("\pElement Label:  ");
  147.     UInt32ToFourByte(info.theLabel, theString);
  148.     DrawString(theString);
  149.  
  150.     MoveTo(r.left, r.top + 105);
  151.     DrawString("\pElement Kind:  ");
  152.     UInt32ToFourByte(info.theKind, theString);
  153.     DrawString(theString);
  154.  
  155.     MoveTo(r.left, r.top + 120);
  156.     DrawString("\pElement Name:  ");
  157.     DrawString(info.theString);
  158.  
  159.     MoveTo(r.left, r.top + 135);
  160.     ISpDeviceReference device;
  161.     ISpElement_GetDevice(gElement, &device);
  162.     ISpDeviceDefinition device_def;
  163.     ISpDevice_GetDefinition(device, sizeof(ISpDeviceDefinition), &device_def);
  164.     DrawString("\pDevice Info:  ");
  165.     DrawString(device_def.deviceName);
  166.  
  167.     DrawString("\p (");
  168.     UInt32ToFourByte(device_def.theDeviceClass, theString);
  169.     DrawString(theString);
  170.     DrawString("\p) (");
  171.     UInt32ToFourByte(device_def.theDeviceIdentifier, theString);
  172.     DrawString(theString);
  173.     DrawString("\p) (");
  174.     UInt32ToFourByte(device_def.permanentID, theString);
  175.     DrawString(theString);
  176.     DrawString("\p) (");
  177.     UInt32ToHexString(device_def.flags, theString);
  178.     DrawString(theString);
  179.     DrawString("\p)");
  180.  
  181.     MoveTo(r.left, r.top + 150);
  182.     OSStatus getConfigStatus = noErr;
  183.     switch (info.theKind)
  184.     {
  185.         case kISpElementKind_Button:
  186.             ISpButtonConfigurationInfo    buttonInfo;
  187.             getConfigStatus = ISpElement_GetConfigurationInfo(gElement, sizeof (buttonInfo), &buttonInfo);
  188.             
  189.             if (getConfigStatus == noErr)
  190.             {
  191.                 DrawString("\pButton Ordering:  ");
  192.                 NumToString (buttonInfo.id, theString);
  193.                 DrawString(theString);
  194.             }
  195.             break;
  196.             
  197.         case kISpElementKind_DPad:
  198.             ISpDPadConfigurationInfo dpadInfo;
  199.             getConfigStatus = ISpElement_GetConfigurationInfo(gElement, sizeof (dpadInfo), &dpadInfo);
  200.             
  201.             if (getConfigStatus == noErr)
  202.             {
  203.             DrawString("\pDPad Ordering:  ");
  204.             NumToString (dpadInfo.id, theString);
  205.             DrawString(theString);
  206.             
  207.             MoveTo(r.left, r.top + 165);
  208.             DrawString("\pIs Four-Way Pad:  ");
  209.             if (dpadInfo.fourWayPad)
  210.                 DrawString("\pTrue");
  211.             else
  212.                 DrawString("\pFalse");
  213.             }
  214.             break;
  215.             
  216.         case kISpElementKind_Axis:
  217.             ISpAxisConfigurationInfo    axisInfo;
  218.             getConfigStatus = ISpElement_GetConfigurationInfo(gElement, sizeof (axisInfo), &axisInfo);
  219.             
  220.             if (getConfigStatus == noErr)
  221.             {
  222.                 DrawString("\pAxis Is Symetric:  ");
  223.                 if (axisInfo.symetricAxis)
  224.                     DrawString("\pTrue");
  225.                 else
  226.                     DrawString("\pFalse");
  227.             }
  228.             break;
  229.         
  230.         case kISpElementKind_Delta:
  231.             DrawString("\pNo Configuration for kISpElementKind_Delta kind  ");
  232.             break;
  233.  
  234.         case kISpElementKind_Movement:
  235.             DrawString("\pNo Configuration for kISpElementKind_Movement kind  ");
  236.             break;
  237.  
  238.         case kISpElementKind_Virtual:
  239.             DrawString("\pNo Configuration for kISpElementKind_Virtual kind  ");
  240.             break;
  241.     }
  242.     
  243.     if (getConfigStatus != noErr)
  244.     {
  245.         DrawString("\pISpElement_GetConfigurationInfo error:  ");
  246.         NumToString (getConfigStatus, theString);
  247.         DrawString(theString);
  248.     }
  249.  
  250. }